package com.sc.nft.dao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.OrderGasShareConfig;
import com.sc.nft.mapper.OrderGasShareConfigMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * @author 刘国航
 * @desc
 * @since 2024/10/21 11:11
 */
@Slf4j
@Repository
public class OrderGasShareConfigDao extends ServiceImpl<OrderGasShareConfigMapper, OrderGasShareConfig> {

    /**
     * 根据藏品id查询
     *
     * @param collectionId
     * @return
     */
    public List<OrderGasShareConfig> listByCollectionId(Long collectionId) {
        LambdaQueryWrapper<OrderGasShareConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrderGasShareConfig::getCollectionId, collectionId);
        return list(queryWrapper);
    }

    /**
     * 根据状态查询
     *
     * @param status
     * @return
     */
    public List<OrderGasShareConfig> listByStatus(Boolean status) {
        LambdaQueryWrapper<OrderGasShareConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrderGasShareConfig::getStatus, status);
        return list(queryWrapper);
    }

    public Page<OrderGasShareConfig> page(Page page, String shareName, Long collectionId) {
        LambdaQueryWrapper<OrderGasShareConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(shareName), OrderGasShareConfig::getShareName, shareName);
        queryWrapper.eq(Objects.nonNull(collectionId), OrderGasShareConfig::getCollectionId, collectionId);
        queryWrapper.orderByDesc(OrderGasShareConfig::getId);
        return page(page, queryWrapper);
    }

}
